//手动制造30条数据
var datas = [];
var files = [];
function getTables() {

    var ajax = new $ax("/meeting/queryHDAll", function (data) {
        // 成功
        if (data.status == "true") {

            datas = data.list;
            files = data.files;
        } else {
            // mui.alert(data.message);
        }

    }, function (data) {
        // 失败
        alert("访问失败");
        errorAjax();

    });

    ajax.setToken(cookie.get("token"));
    ajax.start();
}


$(function () {
    getTables();
    $('#reportTable').bootstrapTable({
        method: 'post',
        cache: false,

        striped: true,
        pagination: true,
        pageSize: 10,
        pageNumber: 1,
        pageList: [10, 20, 50, 100, 200, 500],
        sidePagination: 'client',
        search: true,
        showColumns: true,
        showRefresh: false,
        showExport: false,
        exportTypes: ['csv', 'txt', 'xml'],
        singleSelect: true,
        clickToSelect: true,
        columns:
            [
                {field: "checked", checkbox: true},
                {field: "id", title: "测试姓名id", align: "center", valign: "middle", sortable: "true", visible: false},
                {field: "title", title: "标题", align: "center", valign: "middle", sortable: "true"},
                {
                    field: "conferenceTime",
                    title: "会议时间",
                    align: "center",
                    valign: "middle",
                    sortable: "true",
                    formatter: function (value, row, index) {
                        return formatDateTimeYMDHM(value)
                    }
                },
                {
                    field: "creationTime",
                    title: "创建时间",
                    align: "center",
                    valign: "middle",
                    sortable: "true",
                    formatter: function (value, row, index) {
                        return formatDateTimeYMDHM(value)
                    }
                },
                {field: "meetingPlace", title: "会议地点", align: "center", valign: "middle", sortable: "true"},
                {field: "host", title: "主持人", align: "center", valign: "middle", sortable: "true"},
                {field: "convener", title: "召集者", align: "center", valign: "middle", sortable: "true"},
                {field: "conferenceContent", title: "会议内容", align: "center", valign: "middle", sortable: "true"},
                {field: "sex", title: "附件1", align: "center", valign: "middle", sortable: "true" ,formatter: actionFormatterFile1},
                {field: "sex", title: "附件2", align: "center", valign: "middle", sortable: "true" ,formatter: actionFormatterFile2},

                {field: "sex", title: "查看参与人", align: "center", valign: "middle", sortable: "true" ,formatter: showParticipate},

            ],
        data: datas

    });
});

function getSelect() {

    var selectContent = $('#reportTable').bootstrapTable('getSelections')[0];
    if (typeof(selectContent) == 'undefined') {
        alert('请选择一列数据!');
        return false;
    } else {
        var r = confirm("您确定删除吗?");
        if (r == true) {
            // 确定
            var ajax = new $ax("/meeting/deleteID", function (data) {
                // 成功
                if (data.status == "true") {
                    alert("删除成功");
                    window.location.reload();
                } else {
                    // mui.alert(data.message);
                    alert("删除失败");
                }

            }, function (data) {
                // 失败
                alert("访问失败");
                errorAjax();
                alert("删除失败");
            });

            ajax.setToken(cookie.get("token"));
            ajax.set("id", selectContent.id);
            ajax.start();
        }
        else {

        }
        alert();
        console.info(selectContent);
    }

}

// 更新
function updateMeeting() {
    var selectContent = $('#reportTable').bootstrapTable('getSelections')[0];
    if (typeof(selectContent) == 'undefined') {
        alert('请选择一列数据!');
        return false;
    } else {
        window.location.href = 'updateMeeting.html?id=' + selectContent.id;
    }
}

// 删除公文
function delmeeting(id) {


}

function actionFormatterFile1(value, row, index) {

    var result = "";
    var rowFiles = files[row.fileTime];
    if(rowFiles != null){
        result = "<a href=\"\\yd\\meeting\\"+rowFiles[0].noticeFileName+"\">"+rowFiles[0].noticeFileName+"</a>";
    }

    return result;
}
function actionFormatterFile2(value, row, index) {
    var result = "";
    var rowFiles = files[row.fileTime];
    if(rowFiles != null && rowFiles.length == 2){
        result = "<a href=\"\\yd\\meeting\\"+rowFiles[0].noticeFileName+"\">"+rowFiles[1].noticeFileName+"</a>";
    }

    return result;
}

// 查看参与人状态
function showParticipate(value, row, index) {

    var result = "<a href=\"participate.html?time="+row.fileTime+"&id="+row.id+"\">查看</a>";;


    return result;
}

//return y + '-' + m + '-' + d +' '+h+':'+minute;
function formatDateTimeYMDHM(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
};